package com.controller;

import com.pojo.Result;
import com.pojo.Tags;
import com.service.TagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/tags")
public class TagsController {

    @Autowired
    private TagsService tagsService;

    @PostMapping
    public Result<Void> createTag(@RequestBody Tags tag) {
        return tagsService.createTag(tag);
    }

    @PutMapping("/{id}")
    public Result<Void> updateTag(@PathVariable Integer id, @RequestBody Tags tag) {
        tag.setId(id);
        return tagsService.updateTag(tag);
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteTag(@PathVariable Integer id) {
        return tagsService.deleteTag(id);
    }

    @GetMapping("/{id}")
    public Result<Tags> getTagById(@PathVariable Integer id) {
        return tagsService.getTagById(id);
    }

    @GetMapping
    public Result<List<Tags>> getAllTags() {
        return tagsService.getAllTags();
    }
}